extends Item

class_name Plant

# 收获进度0-1
var harvestState: float = 0
# 生长速度
var growSpeed: float = 1

# 收获物品
var harvestItem: String = 'res://物品/食物/barries.tscn'
# 收获的数量范围
var harvestAmount: Array = [5, 15]

func _init():
	super()
	add_to_group('Plant')

func _ready():
	pass

func tryHarvest(amount: float) -> bool:
	harvestState += amount / growSpeed
	if harvestState >= 1:
		items.remove(self)
		items.createItems(harvestItem, randi_range(harvestAmount[0], harvestAmount[1]), items.WorldToMapPos(position))
		return true
	return false

func _on_area_2d_input_event(_viewport: Node, event: InputEvent, _shape_idx: int):
	if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
		tasks.addTask(Task.TaskType.harvest, self)
